//
//  MCMemberMViewController.m
//  TLYL
//
//  Created by miaocai on 2017/10/18.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCMemberMViewController.h"
#import "MCMMTableViewCell.h"
#import "MCMMlistModel.h"
#import "MCNaviButton.h"

#import <MJExtension/MJExtension.h>
#import <MJRefresh/MJRefresh.h>
#import "MCRefreshNormalHeader.h"
#import"MCPersonInfViewController.h"
#import "MCGameRecordViewController.h"
#import "MCMMForwordController.h"
#import "MCMMSetingViewController.h"
#import "MCTeamBViewController.h"
#import "MCTeamCViewController.h"
#import "MCZhangBianRecordViewController.h"
#import "MCGameRecordViewController.h"
#import "MCHasPayPwdModel.h"
#import "MCMineViewController.h"
#import "MCGetRandomSecurityModel.h"
#import "MCRetrievePasswordModel.h"
#import "MCGetSecurityStateModel.h"
#import "MCMSecureSettingViewController.h"
#import "MCMineInfoModel.h"
#import "MCModifyPayPasswordViewController.h"
#import "MCBreadcrumbTrailView.h"

typedef void(^MCMineViewControllerCompeletion)(BOOL result, NSDictionary *data );
static NSString *_searchName;
@interface MCMemberMViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,weak)MCTopSelectedView *topSelectedView;

@property (nonatomic,assign) BOOL isShowPopView;
/**listModel 模型*/
@property (nonatomic,strong) MCMMlistModel *listModel;
/**导航条的搜索按钮*/
@property (nonatomic,weak) UIButton *btn;
/**查询当前页*/
@property (nonatomic,strong) NSString *currentPageIndex;
/**查询当前页数量*/
@property (nonatomic,strong) NSString *currentPageSize;
@property (nonatomic,strong) NSDate *minDateEnd;
@property (nonatomic,strong) NSDate *minDateEndStart;



@property (nonatomic,assign) int index;

@property (nonatomic,strong) NSDate *minDateShow;
@property (nonatomic,strong) NSDate *maxDateShow;
@property (nonatomic,strong) NSDate *beginDate;
@property (nonatomic,strong) NSDate *endDate;
//获取所有的密保问题
@property(nonatomic, strong)MCGetRandomSecurityModel * getRandomSecurityModel;
//验证密保答案是否正确
@property(nonatomic, strong)MCRetrievePasswordModel  * retrievePasswordModel;
@property(nonatomic, weak)UIAlertAction *sureAction;
@property(nonatomic, weak)UITextField * textField;
//查询是否已设置密保问题
@property (nonatomic,strong) MCGetSecurityStateModel * getSecurityStateModel;
@property (nonatomic,strong) NSMutableArray *cengJiArray;
@property (nonatomic,strong) NSMutableArray *cengJiModelArray;
@property (nonatomic,strong) MCBreadcrumbTrailView *trailView;
@end

@implementation MCMemberMViewController

#pragma mark --life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"会员管理";
    self.view.backgroundColor = RGB(231, 231, 231);
    [self setUpUI];
    [self addNavRightBtn];
    [self configRequstNormalParmas];

}


-(void)GetSecurityState:(MCMineViewControllerCompeletion)Compeletion{
    __weak __typeof(self)wself = self;
    MCGetSecurityStateModel * getSecurityStateModel = [MCGetSecurityStateModel sharedMCGetSecurityStateModel];
    _getSecurityStateModel=getSecurityStateModel;
    [getSecurityStateModel refreashDataAndShow];
    getSecurityStateModel.callBackSuccessBlock = ^(id manager) {
        wself.getSecurityStateModel.hadSecurityState=[NSString stringWithFormat:@"%@",manager[@"Result"]];
        Compeletion(YES,manager);
    };
    getSecurityStateModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
        wself.getSecurityStateModel.hadSecurityState=nil;
        Compeletion(NO,nil);
    };
}

#pragma mark-密保设置
-(void)delay_GoToMCMSecureSettingViewController{
    MCMSecureSettingViewController *svc=[[MCMSecureSettingViewController alloc]init];
    svc.Type = MCMSecureSettingType_FirstSet;
    self.navigationController.navigationBarHidden=NO;
    [self.navigationController pushViewController:svc animated:YES];
}

#pragma mark-跳转转账
-(void)goToZhuanzhangViewController{
    MCGetSecurityStateModel * getSecurityStateModel = [MCGetSecurityStateModel sharedMCGetSecurityStateModel];
    if (getSecurityStateModel.hadSecurityState.length>0) {
        if ([getSecurityStateModel.hadSecurityState integerValue]==1) {
            //设置资金密码-》退回我的
            [SVProgressHUD showInfoWithStatus:@"请先设置资金密码！"];
            [self performSelector:@selector(delay_GoToMCModifyPayPasswordViewController) withObject:nil/*可传任意类型参数*/ afterDelay:1.0];
            
            
        }else{
            //设置密保
            [SVProgressHUD showInfoWithStatus:@"请先设置密保！"];
            
            
            [self performSelector:@selector(delay_GoToMCMSecureSettingViewController) withObject:nil/*可传任意类型参数*/ afterDelay:1.0];
            
        }
    }else{
        __weak __typeof(self)wself = self;
        [self GetSecurityState:^(BOOL result, NSDictionary *data) {
            if (result) {
                wself.getSecurityStateModel.hadSecurityState=data[@"Result"];
                if ([wself.getSecurityStateModel.hadSecurityState integerValue]==1) {
                    //设置资金密码-》退回我的
                    [SVProgressHUD showInfoWithStatus:@"请先设置资金密码！"];
                    
                    [self performSelector:@selector(delay_GoToMCModifyPayPasswordViewController) withObject:nil/*可传任意类型参数*/ afterDelay:1.0];
                    
                }else{
                    [SVProgressHUD showInfoWithStatus:@"加载失败！"];
                }
            }
        }];
    }
}
#pragma mark-资金密码
-(void)delay_GoToMCModifyPayPasswordViewController{
    //先验证密保问题
    [self enSureSecureQuestion];
    
}

#pragma mark-验证密保
-(void)enSureSecureQuestion{
    __weak __typeof__ (self) wself = self;
    
    MCGetRandomSecurityModel * getRandomSecurityModel = [MCGetRandomSecurityModel sharedMCGetRandomSecurityModel];

    _getRandomSecurityModel=getRandomSecurityModel;
    [BKIndicationView showInView:self.view];
    [getRandomSecurityModel refreashDataAndShow];
    getRandomSecurityModel.callBackSuccessBlock = ^(id manager) {
        NSArray * arr =manager;
        if (arr.count>0) {
            wself.getRandomSecurityModel.dataSource = [MCSecurityQuestionModel mj_objectWithKeyValues:manager[0]];
            [wself popRandomSecurity:wself.getRandomSecurityModel.dataSource];
        }
        
    };
    
    getRandomSecurityModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
    };

}

-(void)popRandomSecurity:(MCSecurityQuestionModel *)model{
    __weak __typeof__ (self) wself = self;
    
    NSString * question = [NSString stringWithFormat:@"\n%@",model.Question];
    //创建UIAlertController 设置标题，信息，样式
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"验证密保问题" message:question preferredStyle:UIAlertControllerStyleAlert];
    
    //添加UITextField
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入答案！";
        textField.keyboardType = UIKeyboardTypeDefault;
        [textField addTarget:wself action:@selector(textFieldChane:) forControlEvents:UIControlEventEditingChanged];
        _textField=textField;
    }];
    
    //创建UIAlertAction对象，设置标题并添加到UIAlertController上
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:nil];
    [alertController addAction:cancelAction];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self retrievePasswordModel:model];
        
    }];
    sureAction.enabled=NO;
    _sureAction=sureAction;
    //设置UIAlertAction对象是否可用
    [alertController addAction:sureAction];
    
    //展现UIAlertController
    [self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark-验证密保答案是否正确
-(void)retrievePasswordModel:(MCSecurityQuestionModel *)model{
    
    __weak __typeof__ (self) wself = self;
    MCMineInfoModel * mineInfoModel=[MCMineInfoModel sharedMCMineInfoModel];
    
    NSString * UserName;
    if (mineInfoModel.UserName.length>1) {
        UserName=mineInfoModel.UserName;
    }else{
        UserName=[[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"];
    }
    NSDictionary * dic = @{
                           @"UserName":UserName,//    是    String    用户名称
                           @"RecoveryMode":@"2",//    是    Int    找回方式（1：按资金密码 2：通过密保答案找回），此处传固定值2
                           @"SecurityID":model.ID,//    是    Int    当前问题的ID值
                           @"Answer":_textField.text//    是    String    用户输入答案
                           };
    MCRetrievePasswordModel * retrievePasswordModel = [[MCRetrievePasswordModel alloc]initWithDic:dic];
    _retrievePasswordModel = retrievePasswordModel;
    [BKIndicationView showInView:self.view];
    [retrievePasswordModel refreashDataAndShow];
    retrievePasswordModel.callBackSuccessBlock = ^(id manager) {
        
        MCModifyPayPasswordViewController * vc =[[MCModifyPayPasswordViewController alloc]init];
        wself.navigationController.navigationBarHidden=NO;
        [wself.navigationController pushViewController:vc animated:YES];
        
    };
    
    retrievePasswordModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
    };
    
    
    
}

-(void)textFieldChane:(UITextField *)tf{
    if (tf.text.length>0) {
        _sureAction.enabled=YES;
    }else{
        _sureAction.enabled=NO;
    }
}


#pragma mark --添加🔍
- (void)addNavRightBtn {
    UIButton *btn = [[UIButton alloc] init];
    [btn setBackgroundImage:[UIImage imageNamed:@"debss"] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn sizeToFit];
    [btn addTarget:self action:@selector(allBtnClick:) forControlEvents:UIControlEventTouchDown];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = rightItem;
}
#pragma mark -- setUpUI
-(void)setUpUI{
    self.automaticallyAdjustsScrollViewInsets = NO;
    MCBreadcrumbTrailView *trailView = [[MCBreadcrumbTrailView alloc] initWithFrame:CGRectMake(0,kStatusBarAndNavigationBarHeight, G_SCREENWIDTH, MC_REALVALUE(30))];
    trailView.backgroundColor = RGB(249, 249, 249);
    self.trailView = trailView;
    NSString *fName = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"];
    [self.cengJiArray addObject:fName];
    MCMMlistModel *item = [[MCMMlistModel alloc] init];
    item.UserName = fName;
    item.UserID = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    [self.cengJiModelArray addObject:item];
    trailView.dataArr = self.cengJiArray;
    trailView.selectedBreadcrumbTrailBlock = ^(NSInteger i) {
        [self.cengJiModelArray removeObjectsInRange:NSMakeRange((i + 1) , self.cengJiArray.count - i -1)];
        [self.cengJiArray removeObjectsInRange:NSMakeRange((i + 1) , self.cengJiArray.count - i -1)];
        MCMMlistModel *m  = [self.cengJiModelArray objectAtIndex:i];
        self.subUserID = [NSString stringWithFormat:@"%d",m.UserID];
        [self loadListData];
        [self.trailView.collection reloadData];
        
        
    };
    [self.view addSubview:trailView];
    

    UITableView *tab = [[UITableView alloc] initWithFrame:CGRectMake(0, MC_REALVALUE(13 + 30) + kStatusBarAndNavigationBarHeight , G_SCREENWIDTH, G_SCREENHEIGHT - kTabBarHeight - kStatusBarAndNavigationBarHeight - MC_REALVALUE(40)) style:UITableViewStylePlain];
    [self.view addSubview:tab];
    tab.backgroundColor = RGB(231, 231, 231);
    self.tableView = tab;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    __weak typeof(self) weakself = self;
    [tab registerClass:[MCMMTableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    self.tableView.mj_header = [MCRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakself loadListData];
    }];

    self.tableView.rowHeight = MC_REALVALUE(245);
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    tab.delegate = self;
    tab.dataSource = self;



}
- (NSMutableArray *)cengJiModelArray{
    if (_cengJiModelArray == nil) {
        _cengJiModelArray = [NSMutableArray array];
        
    }
    return _cengJiModelArray;
}
- (NSMutableArray *)cengJiArray{
    if (_cengJiArray == nil) {
        _cengJiArray = [NSMutableArray array];
        
    }
    return _cengJiArray;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self addNavRightBtn];
    [self loadListData];

    [[NSUserDefaults standardUserDefaults] setObject:@"MCMemberMViewController" forKey:@"MCMemberMViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noti) name:@"MCMemberMViewController" object:nil];
    
}
- (void)noti{
    [self.cengJiModelArray removeLastObject];
    MCMMlistModel *model  = [self.cengJiModelArray lastObject];
    self.subUserID = [NSString stringWithFormat:@"%d",model.UserID];
    [self.cengJiArray removeLastObject];
    [[NSUserDefaults standardUserDefaults] setObject:self.cengJiArray forKey:@"MCMemberMViewControllercengJiArray"];
    [self loadListData];
    [self.trailView.collection reloadData];
    
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"MCMemberMViewController" object:nil];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"MCMemberMViewController"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"MCMemberMViewControllercengJiArray"];

    
    
}

#pragma mark --设置初始化请求数据
- (void)configRequstNormalParmas{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy/MM/dd"];

    self.minDate = [NSDate dateWithTimeIntervalSinceNow:-3600 * 24*365*10];
    self.maxDate = [NSDate date];
       
    
    self.index = 1;
    self.currentPageIndex = @"1";
    if (self.subUserID == nil || [self.subUserID isEqualToString:@""]) {
        self.subUserID = [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
    }
    if (self.LikeUserName != nil && ![self.LikeUserName isEqualToString:@""]) {
        
    }
    if (self.TreeType == 0) {
        self.TreeType = 2;
    }
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comps = nil;
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:[NSDate dateWithTimeIntervalSinceNow:-24*3600]];
    NSDate *localDate = [[NSDate dateWithTimeIntervalSinceNow:-24*3600] dateByAddingTimeInterval: interval];
    comps = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth fromDate:localDate];
    [comps setYear:comps.year -10];
    self.minDate = [calendar dateFromComponents:comps];
    self.minDateEnd = self.minDate;
    self.minDateEndStart = self.minDate;

    self.minDateShow = [NSDate date];
    self.maxDateShow = [NSDate date];
    if (self.beginDate || self.endDate) {
        NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
        [dataFormatter setDateFormat:@"yyyy/MM/dd"];
        self.popView.endDateLabDetail.text =  [dataFormatter stringFromDate:self.endDate];
        self.popView.startDateLabDetail.text =  [dataFormatter stringFromDate:self.beginDate];
    } else {
        self.beginDate = self.minDate;
        self.endDate = self.maxDate;
     
    }
 
}
#pragma mark --发送请求
-(void)loadListData{


    [self.tableViewDataArray removeAllObjects];
    self.tableView.mj_footer.hidden=NO;
    self.index = 1;
    __weak typeof(self) weakself = self;
    MCMMlistModel *listModel = [[MCMMlistModel alloc] init];
    self.listModel = listModel;
    listModel.TreeType = self.TreeType;
    listModel.CurrentPageIndex = @"1";
    listModel.CurrentPageSize = @"15";
    if ([_searchName isEqualToString:@""] || _searchName == nil) {
       listModel.LikeUserName = self.LikeUserName;
    } else {
        listModel.LikeUserName = _searchName;
    }
    
    listModel.subUserID = self.subUserID;
    NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
    [dataFormatter setDateFormat:@"yyyy/MM/dd"];
    NSString *dateTemps = [dataFormatter stringFromDate:self.beginDate];
    NSString *dateTempe = [dataFormatter stringFromDate:self.endDate];
    listModel.BeginDate = [NSString stringWithFormat:@"%@ 00:00:00",dateTemps];
    listModel.EndDate = [NSString stringWithFormat:@"%@ 23:59:59",dateTempe];
    [BKIndicationView showInView:self.view];
    [listModel refreashDataAndShow];
    
   
    
    listModel.callBackSuccessBlock = ^(id manager) {
        [weakself tableViewEndRefreshing];
        weakself.tableViewDataArray = [MCMMlistModel mj_objectArrayWithKeyValuesArray:manager[@"MyteamList"]];
        [weakself shouldShowExceptionViewWithManger:manager];
       
    };
    listModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
         [weakself tableViewEndRefreshing];
         [weakself showExcaptionView:errorCode];
      
    
    };
    
}
- (void)loadMoreData{

    self.tableView.mj_footer.hidden=NO;
    self.listModel.CurrentPageIndex = [NSString stringWithFormat:@"%d",++self.index];
    WS(weakSelf);
    
    self.listModel.callBackSuccessBlock = ^(id manager) {
        [weakSelf tableViewEndRefreshing];
        NSArray *arr = [MCMMlistModel mj_objectArrayWithKeyValuesArray:manager[@"MyteamList"]];
        [weakSelf.tableViewDataArray addObjectsFromArray:arr];
        [weakSelf shouldShowExceptionViewWithManger:manager];
        [weakSelf tableViewEndRefreshing];
    };
    self.listModel.callBackFailedBlock = ^(id manager, NSDictionary *errorCode) {
        [weakSelf tableViewEndRefreshing];
        [weakSelf showExcaptionView:errorCode];
    };
    [BKIndicationView showInView:self.view];
    [self.listModel refreashDataAndShow];
}

- (void)tableViewEndRefreshing{
    [self.tableView.mj_footer endRefreshing];
    [self.tableView.mj_header endRefreshing];
}

#pragma mark -- tableView delegate datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.tableViewDataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MCMMTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.dataSource = self.tableViewDataArray[indexPath.row];
    MCMMlistModel * model = self.tableViewDataArray[indexPath.row];
   
    __weak MCMMTableViewCell *weakcell = cell;
    __weak typeof(self) weakself = self;
    cell.btnClickBlock = ^(NSInteger index) {
         UIViewController *vc = nil;
        switch (index) {
               
            case 101://个人资料
            {
                vc = [[MCPersonInfViewController alloc] init];
               MCPersonInfViewController *pvc = (MCPersonInfViewController *)vc;
                pvc.dataSource = weakcell.dataSource;
            }
                break;
            case 102://投注记录
            {
                vc = [[MCGameRecordViewController alloc] init];
                MCGameRecordViewController *pvc = (MCGameRecordViewController *)vc;
                pvc.subUserName = weakcell.dataSource.UserName;
                pvc.teamViewContoller = YES;
                pvc.UserName = model.UserName;
                pvc.subUserID = [NSString stringWithFormat:@"%d",weakcell.dataSource.UserID];
                pvc.mmViewContoller = YES;
              
            }
                break;
            case 103://帐变记录
            {
                vc = [[MCZhangBianRecordViewController alloc] init];
                MCZhangBianRecordViewController *pvc = (MCZhangBianRecordViewController *)vc;
                pvc.subUserName = weakcell.dataSource.UserName;
                pvc.subUserID =  [NSString stringWithFormat:@"%d",weakcell.dataSource.UserID];
                pvc.mmViewContoller = YES;
            }
                break;
            case 104://转账充值
            {

                MCHasPayPwdModel *payModel = [MCHasPayPwdModel sharedMCHasPayPwdModel];
                if([payModel.PayOutPassWord isEqualToString:@"0"]){
                    [self goToZhuanzhangViewController];
                }else{
                    vc = [[MCMMForwordController alloc] init];
                    MCMMForwordController *pvc = (MCMMForwordController *)vc;
                    pvc.dataSource = weakcell.dataSource;
                }
            
            }
                break;
            case 105://返点设置
            {
    
                    vc = [[MCMMSetingViewController alloc] init];
                    MCMMSetingViewController *pvc = (MCMMSetingViewController *)vc;
                    pvc.dataSource = weakcell.dataSource;
              
                
                
            }
                break;
            default:
                break;
        }
           [weakself.navigationController pushViewController:vc animated:YES];
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MCMMlistModel *model = self.tableViewDataArray[indexPath.row];
    
    NSString *str = ((model.Category & 64) == 64) ? @"会员" : @"代理";
    if ([str isEqualToString:@"会员"]) {
        
        [SVProgressHUD showInfoWithStatus:@"会员没有下级！"];
        return;
    }
    self.subUserID = [NSString stringWithFormat:@"%d",model.UserID];
    if (![self.cengJiArray containsObject:model.UserName]) {
         [self.cengJiArray addObject:model.UserName];
        [self.cengJiModelArray addObject:model];
    }
  
    [self.trailView.collection reloadData];
    _searchName = @"";
    self.LikeUserName = @"";
    [self loadListData];
  
}
#pragma  mark -- touch event
- (void)tap{
    self.isShowPopView=NO;
    self.popView.hidden = YES;
    [self.viewPop hiden];
}
- (void)allBtnClick:(UIButton *)btn{
    if (_isShowPopView) {
        _isShowPopView=NO;
        [self.popView hidePopView];
    }else{
        _isShowPopView=YES;
        [self.view bringSubviewToFront:self.popView];

            typeof(self) weakself = self;
            self.popView.lotteryBlock = ^{
                [weakself.viewPop show];
            };
            self.popView.searchBtnBlock = ^(NSString *str) {
                weakself.LikeUserName = str;
                if (![str isEqualToString:@""]) {
                    weakself.popView.startDateLabDetail.text = @"";
                    weakself.popView.endDateLabDetail.text = @"";
                    weakself.beginDate = [NSDate dateWithTimeIntervalSinceNow:-3600 * 24*365*10];
                    weakself.endDate = [NSDate date];
                }

                self.subUserID = [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
                [self.cengJiModelArray removeAllObjects];
                [self.cengJiArray removeAllObjects];
                
                
                NSString *fName = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"];
                [self.cengJiArray addObject:fName];
                MCMMlistModel *item = [[MCMMlistModel alloc] init];
                item.UserName = fName;
                item.UserID = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
                [self.cengJiModelArray addObject:item];
                [self.trailView.collection reloadData];
                _isShowPopView=NO;
     
                    _searchName = @"";
                  [weakself loadListData];
                

            };

            [weakself datePickerCallBack];
            [self.popView showPopView];
        
    }
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"MCMemberMViewController"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"MCMemberMViewControllercengJiArray"];
    NSLog(@"----MCMemberMViewController --dealloc");
}
#pragma mark -- event callback
- (void)datePickerCallBack{
    typeof(self) weakself = self;
    self.popView.startDateBlock = ^{
        weakself.minDate = weakself.minDateEnd;
     
        [weakself cancelDatePicker];;
        weakself.datePicker.sureBlock = ^(NSString *selectDateStr) {
            weakself.popView.startDateLabDetail.text = selectDateStr;
            NSDateFormatter *dataFormatter = [weakself dateFormat];
            weakself.beginDate = [dataFormatter dateFromString:selectDateStr];
            weakself.minDateEndStart = weakself.beginDate;
            weakself.minDateShow = weakself.beginDate;
            [weakself cancelDatePickerAnimate];
        };
        weakself.datePicker.showDate = weakself.minDateShow;
    };
    
    self.popView.endDateBlock = ^{
        [weakself.viewPop hiden];
        weakself.minDate = weakself.minDateEndStart;
        weakself.datePicker.showDate = weakself.maxDateShow;
       [weakself cancelDatePicker];
        weakself.datePicker.sureBlock = ^(NSString *selectDateStr) {
            weakself.popView.endDateLabDetail.text = selectDateStr;
            NSDateFormatter *dataFormatter = [weakself dateFormat];
            weakself.endDate = [dataFormatter dateFromString:selectDateStr];
            weakself.maxDateShow = weakself.endDate;
            [weakself cancelDatePickerAnimate];
        };
        
    };
    
}



- (MCMMPopView *)popView{
    
    if (_popView == nil) {
        MCMMPopView * popView = [[MCMMPopView alloc] init];
        [self.view addSubview:popView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
        [popView addGestureRecognizer:tap];
        _popView = popView;
    }
    return _popView;
}

- (MCMMIputView *)viewPop{
    if (_viewPop == nil) {
        
        MCMMIputView *viewStatus = [[MCMMIputView alloc] init];
        [self.navigationController.view addSubview:viewStatus];
        _viewPop = viewStatus;
    }
    return _viewPop;
}




@end
